package com.lans.binary;

/**
 * @author: lans
 * @date: 2025/2/27
 * @name: 刘宇
 */
public class Node {

    public int no;

    public String name;

    public Node left;

    public Node right;

    public Node(int no, String name) {
        this.no = no;
        this.name = name;
    }

    //前序遍历 先输出父节点再输出左节点再输出右节点
    public void preSelect(){
        System.out.println("父节点:  "+this);
        if(this.left!=null){
            this.left.preSelect();
        }
        if(this.right!=null){
            this.right.preSelect();
        }
    }

    //中序遍历 先输出完左节点 再输出父节点 再输出右节点
    public void infixSelect(){
        if(this.left!=null){
            this.left.infixSelect();
        }
        System.out.println("父节点:  "+this);
        if(this.right!=null){
            this.right.infixSelect();
        }
    }

    //后序遍历 先输出完左节点 再输出完右节点
    public void postSelect(){
        if(this.left!=null){
            this.left.postSelect();
        }
        if(this.right!=null){
            this.right.postSelect();
        }
        System.out.println("父节点:  "+this);
    }

    @Override
    public String toString() {
        return "Node{" +
                "no=" + no +
                ", name=" + name +
                ", left=" + left +
                ", right=" + right +
                '}';
    }
}